package packaging.homework2;

import java.util.Arrays;
public class Student {
    private String id;
    private String name;
    private int  age;
    private String sex;
    private String hobby;
    public Student() {
    }
    public Student(String id, String name, int age, String sex, String hobby) {
        this.setId(id);
        this.setName(name);
        this.setAge(age);
        this.setSex(sex);
        this.setHobby(hobby);
    }
    public String getId() {
        return id;
    }

    public String  setId(String id) {
        return this.id = id;
    }

    public String getName() {
        return name;
    }

    public String  setName(String name) {
        return this.name = name;
    }

    public int getAge() {
        return age;
    }

    public int  setAge(int age) {
        return this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public String  setSex(String sex) {
        return this.sex = sex;
    }

    public String getHobby() {
        return hobby;
    }

    public String setHobby(String hobby) {
        return this.hobby = hobby;
    }
    Student stuList[] =new Student[1];


    public void addStudentDate(Student stu){
        for (int i = 0; i <stuList.length ; i++) {
            if (stuList[i] == null) {
                stuList[i]=stu;
                if (stuList[stuList.length-1]!=null){
                    stuList= Arrays.copyOf(stuList,stuList.length+1);
                    break;
                }
                break;
            }
        }
    }
    public void printStudent(){
        System.out.println("学号\t\t姓名\t\t年龄\t\t性别\t\t业余爱好");
        for (int i = 0; i <stuList.length ; i++) {
            if (stuList[i]!=null) {
                System.out.println(stuList[i].getId()+"\t"+stuList[i].getName()+"\t"
                        +stuList[i].getAge()+"\t"+stuList[i].getSex()+"\t"+stuList[i].getHobby()+"\t");
            }
        }
    }
    public void deleteStudent(String id){
        int index=0;
        for (int i = 0; i <stuList.length-1; i++) {
            if (stuList[i] != null&&stuList[i].getId().equals(id)) {
                index=i;
                break;
            }
        }
        for (int i = index; i <stuList.length-1; i++) {
            stuList[i]=stuList[i+1];
        }
        stuList[stuList.length-1]=null;
    }

}
